﻿Imports System.Data
Imports System.Data.OleDb

Partial Class Main_UploadVideo
    Inherits System.Web.UI.Page

    Protected Sub btnPost_Click(sender As Object, e As System.EventArgs) Handles btnPost.Click
        Dim myGUID As System.Guid
        myGUID = Guid.NewGuid()
        Dim newFileName = myGUID.ToString() + ".wmv"

        If V_File.HasFile Then
            Dim picLocationOnServerHardDisk = Request.MapPath("video") & "/" & newFileName
            V_File.SaveAs(picLocationOnServerHardDisk)
        End If

        Dim oleDbConn As New OleDb.OleDbConnection(ConfigurationManager.ConnectionStrings("myFirstDatabase").ConnectionString)
        Dim SqlString As String = "Insert into tblVideos(Notes,Neighbor,Video,DateSubmitted) Values (@f1,@f2,@f3,@f4)"
        Dim cmd As OleDbCommand = New OleDbCommand(SqlString, oleDbConn)
        Dim SubmittedDate As DateTime = Now()
        Dim format As String = "ddd MMM yyyy"
        cmd.CommandType = CommandType.Text
        cmd.Parameters.AddWithValue("@f1", txtNotes.Text)
        cmd.Parameters.AddWithValue("@f2", User.Identity.Name)
        cmd.Parameters.AddWithValue("@f3", "video/" & V_File.FileName)
        cmd.Parameters.AddWithValue("@f4", SubmittedDate.ToString(format))
        oleDbConn.Open()
        cmd.ExecuteNonQuery()
        Response.Redirect("../Main/UploadSuccess.aspx")
    End Sub
End Class
